//
//  ViewController.m
//  26-masonry
//
//  Created by 王道林 on 16/8/18.
//  Copyright © 2016年 王道林. All rights reserved.
//

#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
#import "Masonry.h"
#define WIDTH self.view.frame.size.width
@interface ViewController ()
@property (nonatomic, strong) AVAudioPlayer *play;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self creatSubview];
    
}
- (void)creatSubview
{
    
    self.view.backgroundColor = [UIColor whiteColor];
    // 背景图片
    UIImageView *imageViewOfBack = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"profile_homepage_default_bg"]];
//    imageViewOfBack.frame = self.view.frame;
    [self.view addSubview:imageViewOfBack];
    
    [imageViewOfBack mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(0);
    }];
    
    
    // 歌名lable
    UILabel *lableOfSingName = [[UILabel alloc] initWithFrame:CGRectMake(150, 20, 100, 40)];
    lableOfSingName.text = @"稻香";
    lableOfSingName.textAlignment = 1;
    lableOfSingName.textColor = [UIColor whiteColor];
    lableOfSingName.font = [UIFont systemFontOfSize:25];
    [imageViewOfBack addSubview:lableOfSingName];
    
    // 标题左边的下箭头
    UIImageView *imageViewOfArrows = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"miniplayer_btn_playlist_close"]];
    imageViewOfArrows.frame = CGRectMake(30, 20, 40, 40);
    [imageViewOfBack addSubview:imageViewOfArrows];
    
    // 标题左侧的点点点
    UIImageView *imageViewOfSet = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Unknown 下午3.29.58"]];
    imageViewOfSet.frame = CGRectMake(350, 20, 40, 40);
    [imageViewOfBack addSubview:imageViewOfSet];
    
    // 歌手
    UILabel *lableOfSinger = [[UILabel alloc] initWithFrame:CGRectMake(150, 70, 70, 45)];
    lableOfSinger.center = CGPointMake(WIDTH / 2.0, 90);
    lableOfSinger.text = @"周杰伦";
    lableOfSinger.textColor = [UIColor whiteColor];
    lableOfSinger.font = [UIFont systemFontOfSize:20];
    lableOfSinger.textAlignment = 1;
    [imageViewOfBack addSubview:lableOfSinger];
    // 小白条
    UIView *viewOfleft = [[UIView alloc] initWithFrame:CGRectMake(100, 70, 25, 1)];
    viewOfleft.center = CGPointMake(WIDTH / 2.0 - 50, 90);
    viewOfleft.backgroundColor = [UIColor whiteColor];
    [imageViewOfBack addSubview:viewOfleft];
    
    UIView *viewOfright = [[UIView alloc] initWithFrame:CGRectMake(200, 70, 25, 1)];
    viewOfright.center = CGPointMake(WIDTH / 2.0 + 50, 90);
    viewOfright.backgroundColor = [UIColor whiteColor];
    [imageViewOfBack addSubview:viewOfright];
    
    // 标准  MV 等button
    
    UIButton *buttonOfNorm = [UIButton buttonWithType:UIButtonTypeCustom];
    [buttonOfNorm setImage:[UIImage imageNamed:@"player_btn_bz_sel_normal"] forState:UIControlStateNormal];
    buttonOfNorm.frame = CGRectMake(WIDTH / 2.0 - 150, 120, 60, 30);
    [self.view addSubview:buttonOfNorm];
    
    UIButton *buttonOfSole = [UIButton buttonWithType:UIButtonTypeCustom];
    [buttonOfSole setImage:[UIImage imageNamed:@"player_btn_copyright_normal"] forState:UIControlStateNormal];
    buttonOfSole.frame = CGRectMake(WIDTH / 2.0 - 70, 120, 60, 30);
    [self.view addSubview:buttonOfSole];
    
    UIButton *buttonOfMV = [UIButton buttonWithType:UIButtonTypeCustom];
    [buttonOfMV setImage:[UIImage imageNamed:@"player_btn_mv_normal"] forState:UIControlStateNormal];
    buttonOfMV.frame = CGRectMake(WIDTH / 2.0 + 10, 120, 60, 30);
    [self.view addSubview:buttonOfMV];
    
    UIButton *buttonOfdts = [UIButton buttonWithType:UIButtonTypeCustom];
    [buttonOfdts setImage:[UIImage imageNamed:@"player_btn_dts_on"] forState:UIControlStateNormal];
    buttonOfdts.frame = CGRectMake(WIDTH / 2.0 + 90, 120, 60, 30);
    [self.view addSubview:buttonOfdts];
    
    // 稻香图片
    UIImageView *imageViewOfPic = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"7c1ed21b0ef41bd5b1fd68dd55da81cb39db3d68"]];
    imageViewOfPic.layer.masksToBounds = YES;
    imageViewOfPic.layer.cornerRadius = 150;
    imageViewOfPic.frame = CGRectMake(50, 160, 300, 300);
    imageViewOfPic.center = CGPointMake(WIDTH / 2.0, 310);
    [imageViewOfBack addSubview:imageViewOfPic];
    
    
    // lable
    UILabel *lableOfSing = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH / 2.0 - 80, 470, 160, 30)];
    lableOfSing.text = @"曲: 周杰伦";
    lableOfSing.textAlignment = 1;
    lableOfSing.font = [UIFont systemFontOfSize:20];
    lableOfSing.textColor = [UIColor whiteColor];
    [imageViewOfBack addSubview:lableOfSing];
    
    // pageControl
    UIPageControl *pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(WIDTH / 2.0 - 80, 500, 160, 20)];
    pageControl.numberOfPages = 3;
    [self.view addSubview:pageControl];
    
    //sliderControl
    UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(50, 520, WIDTH - 100, 40)];
    slider.thumbTintColor = [UIColor colorWithRed:0.25 green:0.74 blue:0.49 alpha:1.00];
    slider.minimumTrackTintColor = [UIColor colorWithRed:0.25 green:0.74 blue:0.49 alpha:1.00];
    slider.minimumValue = 0.0f;
    slider.maximumValue = 1.0f;
    [self.view addSubview:slider];
    
    // buttonOfSuspend
    UIButton *buttonOfSuspend = [UIButton buttonWithType:UIButtonTypeCustom];
    buttonOfSuspend.frame = CGRectMake(WIDTH / 2.0 - 60, 560, 120, 120);
    [self.view addSubview:buttonOfSuspend];
    [buttonOfSuspend setImage:[UIImage imageNamed:@"hp_player_btn_pause_normal"] forState:UIControlStateNormal];
    
    [buttonOfSuspend addTarget:self action:@selector(buttonActionPlay:) forControlEvents:UIControlEventTouchUpInside];
    
    //
    UIButton *buttonOfRetreat = [UIButton buttonWithType:UIButtonTypeCustom];
    buttonOfRetreat.frame = CGRectMake(WIDTH / 2.0 - 110, 600, 50, 50);
    [self.view addSubview:buttonOfRetreat];
    [buttonOfRetreat setImage:[UIImage imageNamed:@"hp_player_btn_pre_normal"] forState:UIControlStateNormal];
    //
    UIButton *buttonOfNext = [UIButton buttonWithType:UIButtonTypeCustom];
    buttonOfNext.frame = CGRectMake(WIDTH / 2.0 + 60, 600, 50, 50);
    [self.view addSubview:buttonOfNext];
    [buttonOfNext setImage:[UIImage imageNamed:@"hp_player_btn_next_normal"] forState:UIControlStateNormal];
    
    //最下面一排button
    
    UIButton *buttonOfFirst = [UIButton buttonWithType:UIButtonTypeCustom];
    buttonOfFirst.frame = CGRectMake(50, 670, 50, 50);
    [self.view addSubview:buttonOfFirst];
    [buttonOfFirst setImage:[UIImage imageNamed:@"concise_icon_favorite_normal"] forState:UIControlStateNormal];
    
    UIButton *buttonOfSecend = [UIButton buttonWithType:UIButtonTypeSystem];
    buttonOfSecend.frame = CGRectMake(130, 670, 50, 50);
    [self.view addSubview:buttonOfSecend];
    buttonOfSecend.tintColor = [UIColor whiteColor];
    [buttonOfSecend setImage:[UIImage imageNamed:@"player_btn_download_pay_normal"] forState:UIControlStateNormal];
    
    UIButton *buttonOfTh = [UIButton buttonWithType:UIButtonTypeSystem];
    buttonOfTh.frame = CGRectMake(200, 670, 50, 50);
    [self.view addSubview:buttonOfTh];
    buttonOfTh.tintColor = [UIColor whiteColor];
    [buttonOfTh setImage:[UIImage imageNamed:@"player_btn_repeat_normal"] forState:UIControlStateNormal];
    
    UIButton *buttonOfFour = [UIButton buttonWithType:UIButtonTypeSystem];
    buttonOfFour.frame = CGRectMake(270, 670, 50, 50);
    [self.view addSubview:buttonOfFour];
    buttonOfFour.tintColor = [UIColor whiteColor];
    [buttonOfFour setImage:[UIImage imageNamed:@"player_btn_share_normal"] forState:UIControlStateNormal];
    
    
    UIButton *buttonOfFive = [UIButton buttonWithType:UIButtonTypeSystem];
    buttonOfFive.frame = CGRectMake(340, 670, 50, 50);
    [self.view addSubview:buttonOfFive];
    buttonOfFive.tintColor = [UIColor whiteColor];
    [buttonOfFive setImage:[UIImage imageNamed:@"discover_smart_songlist"] forState:UIControlStateNormal];
    
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"薛之谦-一半" ofType:@".mp3"];
    // 音乐播放器
    //    NSURL *url = [NSURL fileURLWithPath:path];
    //    _play = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
    
    NSData *data = [NSData dataWithContentsOfFile:path];
    
    _play = [[AVAudioPlayer alloc] initWithData:data error:nil];
    // [self.view addSubview:AVPlay];
    
}

- (void)buttonActionPlay:(UIButton *)button
{
    [_play play];
}

@end